namespace System.Linq.Reactive
{
    class SelectLamdaObservableEx<T, Q> : IObservableEx<Q>
    {
        private readonly IObserverEx<T> f_SourceObserver;
        private readonly Func<T, Q> f_Selector;

        public SelectLamdaObservableEx(IObserverEx<T> observer, Func<T, Q> Selector)
        {
            f_SourceObserver = observer;
            f_Selector = Selector;
        }

        public IObserverEx<Q> GetObserver()
        {
            var observer = new SimpleObserverEx<Q>();
            f_SourceObserver.Reset += observer.OnReset;
            f_SourceObserver.Exception += observer.OnException;
            f_SourceObserver.Complited += observer.OnComplited;
            f_SourceObserver.Next += item => observer.OnNext(f_Selector(item));
            return observer;
        }
    }
}